import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86156
 * Date: 2023-04-09
 * Time: 17:49
 */
public class StudentTest {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        // 添加
        System.out.println("请输入要添加元素个数");
        int count = scanner.nextInt();
        while(count!=0){
            Student stu = new Student();
            System.out.println("请输入学生姓名和年龄");
            stu.setName(scanner.next());
            stu.setAge(scanner.nextInt());
            list.add(stu);
            count--;
        }
        // 遍历
        System.out.print("[");
        for (int i = 0; i < list.size(); i++) {
            Student stu = new Student();
            stu = list.get(i);
            if(i== list.size()-1){
                System.out.print(stu.getName()+" "+stu.getAge());
            }else{
                System.out.print(stu.getName()+" "+stu.getAge()+", ");
            }
        }
        System.out.println("]");
    }
}
